<template>
  <div class="order-manage">
    <div class="header">
      <div class="user-info">
        <div class="logo">
          <span class="logo-icon">📦</span>
          <span>校园快递代拿</span>
        </div>
        <div class="notification-icon" @click="showNotifications">🔔</div>
      </div>
      <div class="welcome-text">订单管理</div>
      <div class="subtitle">查看和管理您的所有订单</div>
    </div>

    <div class="main-content">
      <div class="back-btn" @click="$router.push('/')">
        <span>←</span> 返回首页
      </div>

      <div class="page-title">我的订单</div>

      <div class="order-tabs">
        <div 
          class="tab" 
          :class="{ active: activeTab === 'all' }"
          @click="activeTab = 'all'"
        >全部</div>
        <div 
          class="tab" 
          :class="{ active: activeTab === 'waiting' }"
          @click="activeTab = 'waiting'"
        >待接单</div>
        <div 
          class="tab" 
          :class="{ active: activeTab === 'accepted' }"
          @click="activeTab = 'accepted'"
        >已接单</div>
        <div 
          class="tab" 
          :class="{ active: activeTab === 'picked' }"
          @click="activeTab = 'picked'"
        >已取件</div>
        <div 
          class="tab" 
          :class="{ active: activeTab === 'pending' }"
          @click="activeTab = 'pending'"
        >待支付</div>
        <div 
          class="tab" 
          :class="{ active: activeTab === 'completed' }"
          @click="activeTab = 'completed'"
        >已完成</div>
      </div>

      <!-- 空状态 -->
      <div class="empty-state" v-if="filteredOrders.length === 0">
        <div class="empty-icon">📭</div>
        <div class="empty-text">暂无订单</div>
        <div class="empty-subtext">您还没有任何订单，快去发布您的第一个代拿需求吧！</div>
        <button class="create-order-btn" @click="$router.push('/create-order')">发布代拿需求</button>
      </div>

      <!-- 订单列表 -->
      <div class="order-list" v-else>
        <div class="order-card" v-for="order in filteredOrders" :key="order.id">
          <div class="order-header">
            <div class="order-id">订单号: {{ order.id }}</div>
            <div class="order-status" :class="`status-${order.status}`">
              {{ getStatusText(order.status) }}
            </div>
          </div>

          <div class="order-content">
            <div class="order-info">
              <div class="express-company">{{ order.expressCompany }}</div>
              <div class="item-info">快递单号: {{ order.trackingNumber }}</div>
              <div class="route-info">{{ order.pickupLocation }} → {{ order.deliveryLocation }}</div>
            </div>
            <div class="express-price">¥{{ order.reward }}</div>
          </div>

          <div class="order-actions">
            <button 
              v-if="order.status === 'waiting'" 
              class="action-btn primary-btn"
              @click="cancelOrder(order)"
            >
              取消订单
            </button>
            <button 
              v-if="order.status === 'accepted'" 
              class="action-btn primary-btn"
              @click="contactCourier(order)"
            >
              联系骑手
            </button>
            <button 
              v-if="order.status === 'picked'" 
              class="action-btn primary-btn"
              @click="confirmDelivery(order)"
            >
              确认送达
            </button>
            <button 
              v-if="order.status === 'pending'" 
              class="action-btn primary-btn"
              @click="payOrder(order)"
            >
              立即支付
            </button>
            <button class="action-btn secondary-btn" @click="viewOrderDetail(order)">
              查看详情
            </button>
          </div>
        </div>
      </div>

      <div class="platform-info">
        <p>校园快递代拿平台 © 2025</p>
      </div>
    </div>
  </div>
</template>

<script>
import { ElMessage } from 'element-plus'

export default {
  name: 'OrderManage',
  data() {
    return {
      activeTab: 'all',
      orders: [
        // 这里可以添加一些测试数据，或者保持空数组
        // {
        //   id: 'ORD2025001',
        //   expressCompany: '顺丰速运',
        //   trackingNumber: 'SF1234567890',
        //   pickupLocation: '校门口快递点',
        //   deliveryLocation: '宿舍楼A栋301',
        //   reward: 5,
        //   status: 'waiting',
        //   createTime: '2025-01-12 10:30:00'
        // }
      ]
    }
  },
  computed: {
    filteredOrders() {
      if (this.activeTab === 'all') {
        return this.orders
      }
      return this.orders.filter(order => order.status === this.activeTab)
    }
  },
  methods: {
    showNotifications() {
      ElMessage.info('您有3条未读消息')
    },
    getStatusText(status) {
      const statusMap = {
        waiting: '待接单',
        accepted: '已接单',
        picked: '已取件',
        pending: '待支付',
        completed: '已完成'
      }
      return statusMap[status] || '未知状态'
    },
    cancelOrder(order) {
      ElMessage.info(`取消订单: ${order.id}`)
    },
    contactCourier(order) {
      ElMessage.info(`联系骑手: ${order.id}`)
    },
    confirmDelivery(order) {
      ElMessage.info(`确认送达: ${order.id}`)
    },
    payOrder(order) {
      ElMessage.info(`立即支付: ${order.id}`)
    },
    viewOrderDetail(order) {
      ElMessage.info(`查看订单详情: ${order.id}`)
    }
  }
}
</script>

<style scoped>
.order-manage {
  min-height: 100vh;
  background-color: #f5f7fa;
}

.header {
  background: linear-gradient(135deg, #4a90e2, #5fa8ff);
  color: white;
  padding: 25px 20px;
  text-align: center;
  position: relative;
}

.user-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 15px;
}

.logo {
  display: flex;
  align-items: center;
  font-size: 18px;
  font-weight: 600;
}

.logo-icon {
  margin-right: 8px;
  font-size: 20px;
}

.notification-icon {
  font-size: 20px;
  cursor: pointer;
}

.welcome-text {
  font-size: 20px;
  margin-bottom: 8px;
  font-weight: 600;
}

.subtitle {
  font-size: 14px;
  opacity: 0.9;
}

.main-content {
  padding: 20px;
}

.back-btn {
  display: inline-flex;
  align-items: center;
  margin-bottom: 20px;
  color: #4a90e2;
  cursor: pointer;
  font-size: 14px;
}

.back-btn span {
  margin-left: 5px;
}

.page-title {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 20px;
  color: #333;
}

.order-tabs {
  display: flex;
  background: white;
  border-radius: 12px;
  padding: 5px;
  margin-bottom: 20px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  overflow-x: auto;
}

.tab {
  flex: 1;
  text-align: center;
  padding: 12px 5px;
  font-size: 14px;
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.3s;
  white-space: nowrap;
}

.tab.active {
  background: #4a90e2;
  color: white;
}

.order-list {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.order-card {
  background: white;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  transition: transform 0.3s, box-shadow 0.3s;
}

.order-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.order-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  padding-bottom: 10px;
  border-bottom: 1px solid #f0f0f0;
}

.order-id {
  font-size: 14px;
  color: #666;
}

.order-status {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 20px;
  font-weight: 500;
}

.status-waiting {
  background: #fff9e6;
  color: #f0ad4e;
}

.status-accepted {
  background: #e6f7ff;
  color: #1890ff;
}

.status-picked {
  background: #f6ffed;
  color: #52c41a;
}

.status-pending {
  background: #fff2e8;
  color: #fa8c16;
}

.status-completed {
  background: #f6f6f6;
  color: #8c8c8c;
}

.order-content {
  display: flex;
  justify-content: space-between;
  margin-bottom: 15px;
}

.order-info {
  flex: 1;
}

.express-company {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
}

.express-company::before {
  content: "📦";
  margin-right: 5px;
}

.express-price {
  font-size: 18px;
  font-weight: 600;
  color: #ff6b6b;
}

.item-info {
  font-size: 14px;
  color: #666;
  margin-bottom: 5px;
}

.route-info {
  font-size: 14px;
  color: #666;
  display: flex;
  align-items: center;
}

.route-info::before {
  content: "📍";
  margin-right: 5px;
}

.order-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.action-btn {
  padding: 8px 15px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  border: none;
  transition: all 0.3s;
}

.primary-btn {
  background: #4a90e2;
  color: white;
}

.primary-btn:hover {
  background: #357abd;
}

.secondary-btn {
  background: #f0f0f0;
  color: #666;
}

.secondary-btn:hover {
  background: #e0e0e0;
}

.platform-info {
  margin-top: 30px;
  text-align: center;
  color: #999;
  font-size: 12px;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: #999;
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

.empty-icon {
  font-size: 60px;
  margin-bottom: 20px;
  opacity: 0.5;
}

.empty-text {
  font-size: 16px;
  margin-bottom: 10px;
  color: #666;
}

.empty-subtext {
  font-size: 14px;
  margin-bottom: 25px;
  color: #999;
}

.create-order-btn {
  background: linear-gradient(135deg, #4a90e2, #67b26f);
  color: white;
  border: none;
  padding: 12px 30px;
  border-radius: 25px;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.3s;
  box-shadow: 0 4px 15px rgba(74, 144, 226, 0.3);
}

.create-order-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(74, 144, 226, 0.4);
}
</style>